var timegroup = Ti.UI.createWindow({
	title: 'Timesheet',
    width:Titanium.UI.FILL,
    //backgroundColor:'#FFFFFF',
     backgroundImage:'/images/backgr.jpg',
     orientationModes: [
     		Ti.UI.PORTRAIT,
	        Ti.UI.LANDSCAPE_LEFT,
	        Ti.UI.LANDSCAPE_RIGHT
	    ],
	    barColor: '#378bb9'
});


var tr = Titanium.UI.create2DMatrix();
tr = tr.rotate(90);
 
var drop_button =  Titanium.UI.createButton({
		style:Titanium.UI.iPhone.SystemButton.DISCLOSURE,
		transform:tr
});

var my_combo = Titanium.UI.createTextField({
	hintText:"Project code",
	height:40,
	width:300,
	top:20,
	borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED,
	rightButton:drop_button,
	rightButtonMode:Titanium.UI.INPUT_BUTTONMODE_ALWAYS
});

var txt_PrjName = Titanium.UI.createTextField({
	hintText:"Project Name",
	height:40,
	width:300,
	top:60,
	borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED,
	rightButtonMode:Titanium.UI.INPUT_BUTTONMODE_ALWAYS
});


var view_Check = Ti.UI.createView({
	height:40,
	width:300,
	top: 100
});
    
view_Check.add(Ti.UI.createLabel({text: 'Bill', color:'#FFFFFF',left:2}));
var chk_Bill = Ti.UI.createSwitch({
	value:true
});
view_Check.add(chk_Bill);

var txt_Task = Titanium.UI.createTextField({
	hintText:"Task",
	height:40,
	width:300,
	top:140,
	borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED,
	rightButtonMode:Titanium.UI.INPUT_BUTTONMODE_ALWAYS
});

var txt_Comment = Titanium.UI.createTextField({
	hintText:'Comment',
	height:40,
	width:300,
	top:180,
	borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED,
	rightButtonMode:Titanium.UI.INPUT_BUTTONMODE_ALWAYS
});



var picker_view = Titanium.UI.createView({
	height:251,
	bottom:-251
});
 
var cancel =  Titanium.UI.createButton({
	title:'Cancel',
	style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
});
 
var done =  Titanium.UI.createButton({
	title:'Done',
	style:Titanium.UI.iPhone.SystemButtonStyle.DONE
});
 
var spacer =  Titanium.UI.createButton({
	systemButton:Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE
});
 
var toolbar =  Titanium.UI.createToolbar({
	top:0,
	items:[cancel,spacer,done],
			backgroundGradient: {
		      type: 'linear',
		      colors: ['#b5bdc8','#000000'],//28343b
		      startPoint: {x:0,y:0},
		      endPoint:{x:0,y:35},
		      backFillStart:false}
});
 
var picker = Titanium.UI.createPicker({
		top:43
});
picker.selectionIndicator=true;


//FOR ANIMATION
var slide_in =  Titanium.UI.createAnimation({bottom:0});
var slide_out =  Titanium.UI.createAnimation({bottom:-251});
my_combo.addEventListener('focus', function() {
	picker_view.animate(slide_out);
});
 
drop_button.addEventListener('click',function() {
	picker_view.animate(slide_in);
	my_combo.blur();
});
 
cancel.addEventListener('click',function() {
	picker_view.animate(slide_out);
}); 
 
done.addEventListener('click',function() {
	my_combo.value = picker.getSelectedRow(0).id;
	txt_PrjName.value = picker.getSelectedRow(0).title;
	picker_view.animate(slide_out);
});

//JSON DATA Titanium.UI.createPickerRow({title:'John'}),
var picker_data = [];

var loader = Titanium.Network.createHTTPClient();
var requstUrl = "http://192.168.1.138:89/MasterData.svc/getCompany";

loader.setRequestHeader("enctype", "multipart/form-data");
loader.setRequestHeader("Content-Type", "application/json; charset=utf-8");
loader.onload = function() {
	
	var data = JSON.parse(this.responseText);
	for(var i = 0; i < data.length; i++){
		picker_data[i] = Titanium.UI.createPickerRow({title:data[i].PrjName, id:data[i].PrjCode});
		//picker_data.push(Titanium.UI.createPickerRow({title:data[i].PrjName}));
	}
	picker.add(picker_data);

	picker_view.add(toolbar);

	picker_view.add(picker);

	timegroup.add(my_combo);
	timegroup.add(txt_PrjName);
	timegroup.add(view_Check);
	timegroup.add(txt_Task);
	timegroup.add(txt_Comment);
	timegroup.add(picker_view);
};
loader.open("GET", requstUrl);
loader.send();
///////////
 
timegroup.open({
});